package cn; /**
 * @Author 刘野
 * @create 2021/12/9 22:34
 */


//求两个有序整型数组的交集

public class SuanFa  {

    public static void main(String[] args) {
        SuanFa suanFa = new SuanFa();

int[] a = {1,2,3,4,5,6,7,8,9};
int[] b = {2,4,6,7,8,10};
int[] records = new int[a.length];

   int k = suanFa.aaa(a, b,records);
        for (int i = 0; i < k; i++) {
            System.out.println(records[i]);
        }


    }

    public  int aaa(int[] a,int[] b,int[] records){
        int i=0,j=0,k=0;
        while(i < a.length && j < b.length)
        {
            if(a[i] == b[j] )
            {
                records[k++] = a[i];
                i++;
                j++;
            }
            else if(a[i] > b[j])
            {
                j++;
            }
            else
                i++;
        }
        return k;
    }
}
